<?php
date_default_timezone_set('America/Montreal');
define("VERSION", "0.0.1.10001");
define("TITLE", "SpotDriver Web");
error_reporting(-1);
ini_set('display_errors', 1);
include("Session.php");
include("SpotifyWebAPI.php");
include("SpotifyWebAPIException.php");
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>SPOTDRIVER WEB</title>
</head>
<body>

    <?php
        echo '<h2>Saved Library Albums</h2>';
        $session = new Session('78bed64849d944b995b022f4d49e6b69','7972affa3dd840a79b299663f1ed57e8','http://www.touzel.com/dev/result.php');
        $api = new SpotifyWebAPI();
        $session->requestAccessToken($_GET['code']);
        $api->setAccessToken($session->getAccessToken());
        $saved = $api->getMySavedAlbums();

        echo "<table width='900' border=1>";
        foreach ($saved->items as $item)
        {
            echo '<tr>';
            echo '<td><b>' . $item->album->name . '</b></td>';
            $str_artists = '';
            foreach($item->album->artists as $artist)
            {
                $str_artists = $str_artists.$artist->name;
            }
            echo '<td>' . $str_artists . '</td>';
            echo '<td>' . $item->album->release_date . '</td>';
            echo '<td><a href="#">DELETE!</a></td>';
            echo '</tr>';
        }
        echo "</table>";

        echo '<h2>Add Album to Saved Library</h2>';
    ?>

</body>
</html>
